package com.san.hkhospital.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.san.hkhospital.entity.Hospitalized;
import com.san.hkhospital.service.HospitalizedService;
import com.san.hkhospital.service.impl.HospitalizedServiceImpl;
import com.san.hkhospital.vo.ResultVO;
import com.san.hkhospital.vo.Search;
import com.san.hkhospital.vo.hospitalizedTableVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (hospitalized)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/hospitalized")
public class HospitalizedController {
/**
* 服务对象
*/
@Resource
private HospitalizedServiceImpl hospitalizedServiceImpl;
@Resource
private HospitalizedService hospitalizedService;
/**
* 通过主键查询单条数据
*
* @param hpdId 主键
* @return 单条数据
*/
@GetMapping(value = "/{hpdId}")
public ResultVO selectOne(@PathVariable Integer hpdId) {
    Hospitalized hospitalized =hospitalizedService.find(hpdId);
    if(hospitalized!=null){
        return ResultVO.success("一个住院单查找成功！",hospitalized);
    }else{
        return ResultVO.failed("一个住院单查找失败！");
    }
}
    @GetMapping
    public ResultVO hospitalList(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<hospitalizedTableVo> hospitalizedList = hospitalizedService.findAll();
        PageInfo<hospitalizedTableVo> pageInfo =new PageInfo<hospitalizedTableVo>(hospitalizedList);
        return ResultVO.success("所有住院单查询成功！",pageInfo);
    }
    @PostMapping
    public ResultVO add(@RequestBody Hospitalized hospitalized){
        boolean flag =  hospitalizedService.add(hospitalized);
        if(flag){
            return ResultVO.success("添加住院单成功！");
        }else{
            return ResultVO.failed("添加住院单失败！");
        }
    }
    @PutMapping()
    public ResultVO update(@RequestBody Hospitalized hospitalized){
        boolean flag = hospitalizedService.update(hospitalized);
        if(flag){
            return ResultVO.success("住院单修改成功！");
        }else{
            return ResultVO.failed("住院单修改失败！");
        }
    }
   @RequestMapping("Search")
    public ResultVO Search(@RequestBody Search search, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){
       PageHelper.startPage(pageNum,pageSize);
       List<hospitalizedTableVo> hospitalizedList = hospitalizedService.search(search);
       PageInfo<hospitalizedTableVo> pageInfo =new PageInfo<>(hospitalizedList);
       return ResultVO.success("搜索查询成功！",pageInfo);
   }
   @RequestMapping("ChuyuanKai")
    public ResultVO  ChuyuanKai(@RequestParam Integer hpdId){
     boolean flag = hospitalizedService.chuyuanKai(hpdId);
     if(flag){
         return ResultVO.success("出院成功！");
     }else{
         return ResultVO.success("出院失败！");
     }
   }
    @RequestMapping("ChuyuanJie")
    public ResultVO  ChuyuanJie(@RequestParam Integer hpdId){
        boolean flag = hospitalizedService.chuyuanJie(hpdId);
        if(flag){
            return ResultVO.success("出院成功！");
        }else{
            return ResultVO.success("出院失败！");
        }
    }

    @RequestMapping("Tiaojiancha")
    public ResultVO Tiaojiancha(@RequestParam Integer hpdId){
        return ResultVO.success("详情跳转成功！");
    }
}
